package com.ruoyi.result.controller;

import java.util.List;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiImplicitParam;
import com.ruoyi.result.domain.ResultReward;
import com.ruoyi.result.service.IResultRewardService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 获奖Controller
 * 
 * @author yepanpan
 * @date 2021-03-15
 */
@Api("获奖管理")
@RestController
@RequestMapping("/result/reward")
public class ResultRewardController extends BaseController
{
    @Autowired
    private IResultRewardService resultRewardService;

    /**
     * 查询获奖列表
     */
    @ApiOperation("查询获奖列表")   
    @PreAuthorize("@ss.hasPermi('result:reward:list')")
    @GetMapping("/list")
    public TableDataInfo list(ResultReward resultReward)
    {
        startPage();
        List<ResultReward> list = resultRewardService.selectResultRewardList(resultReward);
        return getDataTable(list);
    }

    /**
     * 导出获奖列表
     */
    @ApiOperation("导出获奖列表")    
    @PreAuthorize("@ss.hasPermi('result:reward:export')")
    @Log(title = "获奖", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(ResultReward resultReward)
    {
        List<ResultReward> list = resultRewardService.selectResultRewardList(resultReward);
        ExcelUtil<ResultReward> util = new ExcelUtil<ResultReward>(ResultReward.class);
        return util.exportExcel(list, "reward");
    }

    /**
     * 获取获奖详细信息
     */
    @ApiOperation("获取获奖详细信息")
    @ApiImplicitParam(name = "id", value = "获奖ID", required = true, dataType = "int", paramType = "path") 
    @PreAuthorize("@ss.hasPermi('result:reward:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(resultRewardService.selectResultRewardById(id));
    }

    /**
     * 新增获奖
     */
    @ApiOperation("新增获奖")
    @PreAuthorize("@ss.hasPermi('result:reward:add')")
    @Log(title = "获奖", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ResultReward resultReward)
    {
        return toAjax(resultRewardService.insertResultReward(resultReward));
    }

    /**
     * 修改获奖
     */
    @ApiOperation("修改获奖")  
    @PreAuthorize("@ss.hasPermi('result:reward:edit')")
    @Log(title = "获奖", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ResultReward resultReward)
    {
        return toAjax(resultRewardService.updateResultReward(resultReward));
    }

    /**
     * 删除获奖
     */
    @ApiOperation("删除获奖")
    @ApiImplicitParam(name = "id", value = "获奖ID", required = true, dataType = "int", paramType = "path") 
    @PreAuthorize("@ss.hasPermi('result:reward:remove')")
    @Log(title = "获奖", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(resultRewardService.deleteResultRewardByIds(ids));
    }
}
